package com.example.testapplication.activity;
import android.app.Service;
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 android.graphics.Bitmap;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.example.testapplication.Constant.Globalconsts;
import com.example.testapplication.Interface.BitmapCallback;
import com.example.testapplication.Interface.MusicInfoCallback;
import com.example.testapplication.MusicModel;
import com.example.testapplication.R;
import com.example.testapplication.utils.UrlFactory;
import com.example.testapplication.application.MusicApplication;
import com.example.testapplication.bean.MusicItem;
import com.example.testapplication.fragment.HotMusicListFragment;
import com.example.testapplication.fragment.NewMusicListFragment;
import com.example.testapplication.service.PlayMusicService;
import com.example.testapplication.utils.BitmapUtils;
import com.example.testapplication.utils.LrcCallback;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
public class TestActivity extends AppCompatActivity implements View.OnClickListener {
private RadioGroup radioGroup;
private RadioButton radioButtonNew;
private RadioButton radioButtonHot;
private ViewPager viewPager;
private ArrayList<Fragment> fragments;
private MainPagerAdapter adapter;
private ServiceConnection conn;
MusicInfoBroadCastReceiver receiver;
private ImageView imgMusicThumb;
private TextView tvMusicTitle;
private RelativeLayout rlPlayMusic;
private ImageView img_play_music_background;
private ImageView img_play_music_thumb;
private SeekBar seekBar;
private TextView tv_play_music_total_time;
private TextView tv_play_music_current_time;
private PlayMusicService.MusicBinder binder;
private MusicApplication app;
private ImageView img_pre_music;
private ImageView img_pause_music;
private ImageView img_next_music;
private MusicModel musicModel = new MusicModel();
private TextView tv_play_music_title;
private TextView tv_play_music_singer;
private TextView img_play_music_lrc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
setViews();
//设置ViewPager适配器
setViewPagerAdapter();
//设置监听
setListeners();
//绑定Service
bindMusicService();
//注册广播接收器
registMusicReceiver();
}
private void setViews() {
radioGroup = findViewById(R.id.radioGroup);
radioButtonNew = findViewById(R.id.radioButtonNew);
radioButtonHot = findViewById(R.id.radioButtonHot);
viewPager = findViewById(R.id.viewpager);
imgMusicThumb = findViewById(R.id.img_music_thumb);
tvMusicTitle = findViewById(R.id.tv_music_title);
rlPlayMusic = findViewById(R.id.rlPlayMusic);
img_play_music_background = findViewById(R.id.img_play_music_background);
img_play_music_thumb = findViewById(R.id.img_play_music_thumb);
seekBar = findViewById(R.id.sk_play_music_progress);
tv_play_music_total_time = findViewById(R.id.tv_play_music_total_time);
tv_play_music_current_time = findViewById(R.id.tv_play_music_current_time);
img_pre_music = findViewById(R.id.img_pre_music);
img_pause_music = findViewById(R.id.img_pause_music);
img_next_music = findViewById(R.id.img_next_music);
tv_play_music_title = findViewById(R.id.tv_play_music_title);
tv_play_music_singer = findViewById(R.id.tv_play_music_singer);
img_play_music_lrc = findViewById(R.id.img_play_music_lrc);
}
private void setViewPagerAdapter() {
//准备Fragment集合作为数据源
fragments = new ArrayList<Fragment>();
//向集合中添加两页
fragments.add(new NewMusicListFragment());
fragments.add(new HotMusicListFragment());
//Activity必须继承自FragmentActivity
adapter = new MainPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(adapter);
}
private void setListeners() {
//viewpager控制radiobutton
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
//当选择某一页时执行该方法
@Override
public void onPageSelected(int position) {
switch (position) {
case 0:
radioButtonNew.setChecked(true);
break;
case 1:
radioButtonHot.setChecked(true);
break;
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
//radiobutton控制viewpager
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (i) {
case R.id.radioButtonNew:
viewPager.setCurrentItem(0);
break;
case R.id.radioButtonHot:
viewPager.setCurrentItem(1);
break;
}
}
});
imgMusicThumb.setOnClickListener(this);
img_pre_music.setOnClickListener(this);
img_pause_music.setOnClickListener(this);
img_next_music.setOnClickListener(this);
//给seekbar加监听
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {//由用户引起
//seekto
binder.seekTo(progress);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.img_music_thumb:
//显示出RelativeLayout
rlPlayMusic.setVisibility(View.VISIBLE);
//弹出
TranslateAnimation animation = new TranslateAnimation(0, 0, rlPlayMusic.getHeight(), 0);
animation.setDuration(500);
rlPlayMusic.setAnimation(animation);
break;
case R.id.img_p