package com.hipad.voice.activity;
import java.util.ArrayList;
import java.util.List;
import com.hipad.voice.activity.personal.PersonalActivity;
import com.hipad.voice.app.AppApplication;
import com.hipad.voice.bean.AlbumSingerData.SingerData.AlbumSoundData;
import com.hipad.voice.main.R;
import com.hipad.voice.service.MusicPlayService;
import com.hipad.voice.view.CircleImageView;
import com.hipad.voice.view.ViewPagerCanNotScroll;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
@SuppressWarnings("deprecation")
public class MainTabActivity extends FragmentActivity {
private LinearLayout mMyBottemSearchBtn, mMyBottemTuanBtn, mMyBottemCheckinBtn, mMyBottemMyBtn, mMyBottemMoreBtn;
private ImageView mMyBottemSearchImg, mMmsBntImg, mMyBottemCheckinImg, mMyBottemMyImg, mMyBottemMoreImg;
private TextView mMyBottemSearchTxt, mMyBottemTuanTxt, mMyBottemCheckinTxt, mMyBottemMyTxt, mMyBottemMoreTxt;
private List<Fragment> list = new ArrayList<Fragment>();
private ViewPagerCanNotScroll mViewPager;
private long mExitTime;
private RelativeLayout PlayBntImg;
public MusicPlayService mService;
public AppApplication application;
private ArrayList<AlbumSoundData> songs;
public int getCurrentListItme;
public AlbumSoundData currtentSong;
private CircleImageView circle_imv_button;
private RotateAnimation anim;
private ImageView imv_play_btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
application = AppApplication.getApp();
setContentView(R.layout.activity_frame);
initView();
}
private void initView() {
mViewPager = (ViewPagerCanNotScroll) findViewById(R.id.FramePager);
mViewPager.setScanScroll(false);
mMyBottemSearchBtn = (LinearLayout) findViewById(R.id.MyBottemSearchBtn);
mMyBottemTuanBtn = (LinearLayout) findViewById(R.id.MyBottemTuanBtn);
mMyBottemCheckinBtn = (LinearLayout) findViewById(R.id.MyBottemCheckinBtn);
mMyBottemMyBtn = (LinearLayout) findViewById(R.id.MyBottemMyBtn);
mMyBottemMoreBtn = (LinearLayout) findViewById(R.id.MyBottemMoreBtn);
mMyBottemSearchImg = (ImageView) findViewById(R.id.MyBottemSearchImg);
mMmsBntImg = (ImageView) findViewById(R.id.MmsBntImg);
mMyBottemCheckinImg = (ImageView) findViewById(R.id.MyBottemCheckinImg);
mMyBottemMyImg = (ImageView) findViewById(R.id.MyBottemMyImg);
mMyBottemMoreImg = (ImageView) findViewById(R.id.MyBottemMoreImg);
mMyBottemSearchTxt = (TextView) findViewById(R.id.MyBottemSearchTxt);
mMyBottemTuanTxt = (TextView) findViewById(R.id.MyBottemTuanTxt);
mMyBottemCheckinTxt = (TextView) findViewById(R.id.MyBottemCheckinTxt);
mMyBottemMyTxt = (TextView) findViewById(R.id.MyBottemMyTxt);
mMyBottemMoreTxt = (TextView) findViewById(R.id.MyBottemMoreTxt);
PlayBntImg = (RelativeLayout) findViewById(R.id.PlayBntImg);
circle_imv_button = (CircleImageView) findViewById(R.id.circle_imv_button);
imv_play_btn = (ImageView) findViewById(R.id.imv_play_btn);
DTBtnOnclick mytouchlistener = new DTBtnOnclick();
mMyBottemSearchBtn.setOnClickListener(mytouchlistener);
mMyBottemTuanBtn.setOnClickListener(mytouchlistener);
mMyBottemCheckinBtn.setOnClickListener(mytouchlistener);
mMyBottemMyBtn.setOnClickListener(mytouchlistener);
mMyBottemMoreBtn.setOnClickListener(mytouchlistener);
// PlayBntImg.setOnClickListener(mytouchlistener);
circle_imv_button.setOnClickListener(mytouchlistener);
initViewPager();
}
public void initViewPager() {
list.add(new MainActivity());
list.add(new SubscribeNewActivity());
list.add(new DownLoadActivity());
list.add(new PersonalActivity());
// mViewPager.setOffscreenPageLimit(3);
mViewPager.setAdapter(pagerAdapter);
mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
initBottemBtn();
if (arg0 == 0) {
// mMyBottemSearchImg.setImageResource(R.drawable.home_select);
// mMyBottemSearchTxt.setTextColor(Color.parseColor("#56c159"));
} else if (arg0 == 1) {
// mMmsBntImg.setImageResource(R.drawable.subscription_select);
// mMyBottemTuanTxt.setTextColor(Color.parseColor("#56c159"));
} else if (arg0 == 2) {
// mMyBottemCheckinImg.setImageResource(R.drawable.learn_select);
// mMyBottemCheckinTxt.setTextColor(Color.parseColor("#56c159"));
} /*
* else if (flag == 3) { mMyBottemMyImg
* .setImageResource(R.drawable.main_index_my_pressed);
* mMyBottemMyTxt.setTextColor(Color.parseColor("#FF8C00"));
* }
*/else if (arg0 == 4) {
// mMyBottemMoreImg.setImageResource(R.drawable.mine_select);
// mMyBottemMoreTxt.setTextColor(Color.parseColor("#56c159"));
}
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
}
FragmentPagerAdapter pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
return list.get(arg0);
}
};
private class DTBtnOnclick implements View.OnClickListener {
@Override
public void onClick(View arg0) {
int mBtnid = arg0.getId();
switch (mBtnid) {
case R.id.MyBottemSearchBtn:
mViewPager.setCurrentItem(0);
initBottemBtn();
mMyBottemSearchImg.setImageResource(R.drawable.main_find_normal);
mMyBottemSearchTxt.setTextColor(Color.parseColor("#d33d3e"));
break;
case R.id.MyBottemTuanBtn:
mViewPager.setCurrentItem(1);
initBottemBtn();
mMmsBntImg.setImageResource(R.drawable.main_subscribe_selected);
mMyBottemTuanTxt.setTextColor(Color.parseColor("#d33d3e"));
break;
case R.id.MyBottemCheckinBtn:
mViewPager.setCurrentItem(2);
initBottemBtn();
mMyBottemCheckinImg.setImageResource(R.drawable.main_index_checkin_pressed);
mMyBottemCheckinTxt.setTextColor(Color.parseColor("#d33d3e"));
break;
case R.id.MyBottemMyBtn:
mViewPager.setCurrentItem(2);
initBottemBtn();
mMyBottemMyImg.setImageResource(R.drawable.main_down_selected);
mMyBottemMyTxt.setTextColor(Color.parseColor("#d33d3e"));
break;
case R.id.MyBottemMoreBtn:
mViewPager.setCurrentItem(3);
initBottemBtn();
mMyBottemMoreImg.setImageResource(R.drawable.main_mine_selected);
mMyBottemMoreTxt.setTextColor(Color.parseColor("#d33d3e"));
break;
case R.id.circle_imv_button:
Log.i("peiwg", "2016年11月22日141023 点我了 ");
if (mService == null) {
mService = application.getmService();
}
songs = mService.getSongs();
getCurrentListItme = mService.getCurrentListItme();
if (songs.size() > 0 || mService.getBroadCastThumb() != "") {
if (songs.size() > getCurrentListItme) {
// 跳转到声音播放界面
currtentSong = songs.get(getCurrentListItme);
if (mService.isPlay()) {
// circle_imv_button.setImageResource(R.drawable.activity_main_tab_playbutton_normal);
} else {
// LoadedButtonImage(currtentSong.thumb);
mService.setCurrentListItme(getCurrentListItme);
mService.setSongs(songs);
mService.playMusic(songs.get(getCurrentListItme).vms_json, 1);
}
Intent intent = new Intent(getApplication(), VoicePlayActivity.class);
intent.putExtra("sounds", songs);
intent.putExtra("position", getCurrentListItme);
intent.putExtra("sid", currtentSong.sid);
startActivity(intent);
// overridePendingTransition(R.anim.pop_enter_anim,0);
} else if (songs.size() == 0 && mService.getBroadCastThumb() != "") {
// 跳转到广播播放界面
Intent intent = new Intent(getApplication(), BroadcastPlayActivity.class);
intent.putExtra("id", currtentSong.id);
startActivity(intent);
}
} else {
Toast.makeText(MainTabActivity.this, "请先选播您喜欢的歌曲", 0).show();
}
break;
}
}
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
if ((System.currentTimeMillis() - mExitTime) > 2000) {
Toast.makeText(this, getResources().getString(R.string.click_down_exit), Toast.LENGTH_SHORT).show();
mExitTime = System.currentTimeMillis();
} else {
finish();
}
}
return true;
}
return super.dispatchKeyEvent(event);
}
private void initBottemBtn() {
mMyBottemSearchImg.setImageResource(R.drawable.search_bottem_search);
mMmsBntImg.setImageResource(R.drawable.search_bottem_tuan);
mMyBottemCheckinImg.setImageResource(R.drawable.search_bottem_checkin);
mMyBottemMyImg.setImageResource(R.drawable.search_bottem_my);
mMyBottemMoreImg.setImageResource(R.drawable.search_bottem_more);
mMyBottemSearchTxt.setTextColor(getResources().getColor(R.color.search_bottem_textcolor));
mMyBottemTuanTxt.setTextColor(getResources().getColor(R.color.search_bottem_textcolor));
mMyBottemCheckinTxt.setTextColor(getResources().getColor(R.color.search_bottem_textcolor));
mMyBottemMyTxt.setTextColor(getResources().getColor(R.color.search_bottem_textcolor));
mMyBottemMoreTxt.setTextColor(getResources().getColor(R.color.search_bottem_textcolor));
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
// Toast.makeText(this, "有见面了,哈哈", 1).show();
if (mService == null) {
mService = application.getmService();
}
if (mService != null) {
songs = mService.getSongs();
getCurrentListItme = mService.getCurrentListItme();
}
if (songs != null) {
if (songs.size() > getCurrentListItme) {
// 加载声音的默认图
currtentSong = songs.get(getCurrentListItme);
LoadedButtonImage(currtentSong.thumb);
// 头像加旋转动画
if (mService.isPlay()) {
// 创建一个旋转动画从0到360 旋转一周,以图片本身中心为轴
anim = new RotateAnimation(0, 360, circle_imv_button.getWidth() / 2,
circle_imv_button.getHeight() / 2);
// 设置动画属性
// 持续时间
anim.setDuration(3000);
// 是否重复
anim.setRepeatCount(Animation.INFINITE);
// 是否添加了匀速
anim.setInterpolator(new LinearInterpolator());
// 启动动画
circle_imv_button.setAnimation(anim);
imv_play_btn.setVisibility(View.GONE);
} else {
circle_imv_button.clearAnimation();
imv_play_btn.setVisibility(View.VISIBLE);
}
}else if(songs.size() == 0 && mService.getBroadCastThumb() != ""){
// 加载广播的默认图
String broadCastThumb = mService.getBroadCastThumb();
LoadedButtonImage(broadCastThumb);
// 头像加旋转动画
if (mService.isPlay()) {
// 创建一个旋转动画从0到360 旋转一周,以图片本身中心为轴
anim = new RotateAnimation(0, 360, circle_imv_button.getWidth() / 2,
circle_imv_button.getHeight() / 2);
// 设置动画属性
// 持续时间
anim.setDuration(3000);
// 是否重复
anim.setRepeatCount(Animation.INFINITE);
// 是否添加了匀速
anim.setInterpolator(new LinearInterpolator());
// 启动动画
circle_imv_button.setAnimation(anim);
imv_play_btn.setVisibility(View.GONE);
} else {
circle_imv_button.clearAnimation();
imv_play_btn.setVisibility(View.VISIBLE);
}
}else{
//什么都不做,显示默认的红色按钮
}
} else {
circle_imv_button.setImageResource(R.drawable.activity_main_tab_playbutton_normal);
circle_imv_button.clearAnimation();
}
}
private void LoadedButtonImage(String url) {
ImageLoader imageloader = ImageLoader.getInstance();
DisplayImageOptions options = new DisplayImageOptions.Builder()
// 缓存到内存
.cacheInMemory(true)
// 设置图片在下载期间显示的图片
.showImageOnLoading(R.drawable.pic_loading)
// 设置图片Uri为空或是错误的时候显示的图片
.showImageForEmptyUri(R.drawable.pic_loading)
// 设置图片加载/解码过程中错误时候显示的图片
.showImageOnFail(R.drawable.pic_loading).build();
imageloader.displayImage(url, circle_imv_button, options);
}
}