package com.qxw.music;
import com.qxw.custom.ImageTextButton;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnTouchListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ViewFlipper;
public class MusicMain extends ActivityGroup implements OnGestureListener,OnTouchListener {
//声明ViewFlipper对象
private ViewFlipper m_ViewFlipper;
//声明GestureDetector对象
private GestureDetector m_GestureDetector;
//声明LocalActivityManager对象
private LocalActivityManager m_ActivityManager;
private static int FLING_MIN_DISTANCE = 100;
private static int FLING_MIN_VELOCITY = 200;
//定义自定义图片加文字按钮ImageTextButton对象
private ImageTextButton now_playing;
private ImageTextButton native_music;
private ImageTextButton network_music;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//设置内容试图
setContentView(R.layout.music_main);
//构建ImageTextButton对象
now_playing = (ImageTextButton) findViewById(R.id.now_playing);
native_music = (ImageTextButton) findViewById(R.id.native_music);
network_music = (ImageTextButton) findViewById(R.id.network_music);
//构建ViewFlipper对象
m_ViewFlipper = (ViewFlipper) findViewById(R.id.fliper);
//获取Activity消息
m_ActivityManager = getLocalActivityManager();
//注册一个用于手势识别的类
m_GestureDetector = new GestureDetector(this);
//添加视图,指定每个视图对应的Activity
m_ViewFlipper.addView((m_ActivityManager.startActivity("", new Intent(MusicMain.this,NowPlay.class)).getDecorView()),0);
m_ViewFlipper.addView((m_ActivityManager.startActivity("", new Intent(MusicMain.this,NativeMusic.class)).getDecorView()),1);
m_ViewFlipper.addView((m_ActivityManager.startActivity("", new Intent(MusicMain.this,NetworkMusic.class)).getDecorView()),2);
//给ViewFlipper设置一个listener
m_ViewFlipper.setOnTouchListener(this);
//默认为正在播放页面并设置图标
now_playing.setIcon(R.drawable.frame_player_press);
//设置相应元素索引显示的子视图
m_ViewFlipper.setDisplayedChild(0);
//允许长按住ViewFlipper,这样才能识别拖动等手势
m_ViewFlipper.setLongClickable(true);
//监听
BindListener();
}
/**
* 监听本Activity中所要监听的对象
*/
public void BindListener()
{
//监听正在播放按钮事件
now_playing.setOnClickListener(new ImageTextButton.OnClickListener()
{
public void onClick(View v)
{
//点击之后改变图片
now_playing.setIcon(R.drawable.frame_player_press);
native_music.setIcon(R.drawable.frame_local_normal);
network_music.setIcon(R.drawable.frame_internet_normal);
// //设置View进入屏幕时候使用的动画
// m_ViewFlipper.setInAnimation(inFromRightAnimation());
// //设置View退出屏幕时候使用的动画
// m_ViewFlipper.setOutAnimation(outToLeftAnimation());
//设置相应元素索引显示的子视图
m_ViewFlipper.setDisplayedChild(0);
}
});
//监听本地歌曲按钮事件
native_music.setOnClickListener(new ImageTextButton.OnClickListener()
{
public void onClick(View v)
{
//点击之后改变图片
now_playing.setIcon(R.drawable.frame_player_normal);
native_music.setIcon(R.drawable.frame_local_press);
network_music.setIcon(R.drawable.frame_internet_normal);
//设置View进入屏幕时候使用的动画
// m_ViewFlipper.setInAnimation(inFromRightAnimation());
// //设置View退出屏幕时候使用的动画
// m_ViewFlipper.setOutAnimation(outToLeftAnimation());
//设置相应元素索引显示的子视图
m_ViewFlipper.setDisplayedChild(1);
}
});
//监听网络歌曲按钮事件
network_music.setOnClickListener(new ImageTextButton.OnClickListener()
{
public void onClick(View v)
{
//点击之后改变图片
now_playing.setIcon(R.drawable.frame_player_normal);
native_music.setIcon(R.drawable.frame_local_normal);
network_music.setIcon(R.drawable.frame_internet_press);
// //设置View进入屏幕时候使用的动画
// m_ViewFlipper.setInAnimation(inFromRightAnimation());
// //设置View退出屏幕时候使用的动画
// m_ViewFlipper.setOutAnimation(outToLeftAnimation());
//设置相应元素索引显示的子视图
m_ViewFlipper.setDisplayedChild(2);
}
});
}
/**
* 定义从右侧进入的动画效果
* @return
*/
public Animation inFromRightAnimation()
{
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(500);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
/**
* 定义从左侧退出的动画效果
* @return
*/
public Animation outToLeftAnimation()
{
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
/**
* 定义从左侧进入的动画效果
* @return
*/
public Animation inFromLeftAnimation()
{
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(500);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
/**
* 定义从右侧退出时的动画效果
* @return
*/
public Animation outToRightAnimation()
{
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(500);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
//当像左侧滑动的时候
if(e1.getX()-e2.getX()>FLING_MIN_DISTANCE && Math.abs(velocityX)>FLING_MIN_VELOCITY)
{
//设置View进入屏幕时候使用的动画
m_ViewFlipper.setInAnimation(inFromRightAnimation());
//设置View退出屏幕时候使用的动画
m_ViewFlipper.setOutAnimation(outToLeftAnimation());
//下一个页面
m_ViewFlipper.showNext();
//获取相应元素索引显示的子视图
int child = m_ViewFlipper.getDisplayedChild();
switch(child)
{
case 0:
now_playing.setIcon(R.drawable.frame_player_press);
native_music.setIcon(R.drawable.frame_local_normal);
network_music.setIcon(R.drawable.frame_internet_normal);
break;
case 1:
now_playing.setIcon(R.drawable.frame_player_normal);
native_music.setIcon(R.drawable.frame_local_press);
network_music.setIcon(R.drawable.frame_internet_normal);
break;
case 2:
now_playing.setIcon(R.drawable.frame_player_normal);
native_music.setIcon(R.drawable.frame_local_normal);
network_music.setIcon(R.drawable.frame_internet_press);
break;
case 3:
now
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android ActivityGroup demo (104个子文件)
resources.ap_ 214KB
MusicTest.apk 224KB
MusicMain.class 6KB
MusicMain.class 6KB
R$color.class 2KB
R$color.class 2KB
NativeMusicInfo2$1.class 2KB
NativeMusicInfo$1.class 2KB
NativeMusicInfo$1.class 2KB
ImageTextButton.class 2KB
ImageTextButton.class 2KB
NativeMusicInfo$2.class 2KB
NativeMusic$1.class 2KB
NativeMusic$1.class 2KB
C_SlidingDrawer.class 2KB
C_SlidingDrawer.class 2KB
NowPlay.class 1KB
NowPlay.class 1KB
MusicMain$3.class 1KB
MusicMain$2.class 1KB
MusicMain$1.class 1KB
MusicMain$3.class 1KB
MusicMain$2.class 1KB
MusicMain$1.class 1KB
NativeMusicInfo.class 1KB
R$drawable.class 1024B
R$drawable.class 1024B
NativeMusicInfo2.class 969B
NativeMusicInfo.class 964B
NativeMusic.class 944B
NativeMusic.class 944B
NowPlay$2.class 856B
NowPlay$2.class 856B
NowPlay$1.class 854B
NowPlay$1.class 854B
R$id.class 807B
R$id.class 778B
R$string.class 621B
R$string.class 621B
R$layout.class 573B
R.class 539B
R.class 539B
R$layout.class 531B
NetworkMusic.class 507B
NetworkMusic.class 507B
R$attr.class 325B
R$attr.class 325B
.classpath 288B
classes.dex 17KB
MusicMain.java 11KB
R.java 5KB
NativeMusicInfo.java 3KB
C_SlidingDrawer.java 2KB
ImageTextButton.java 2KB
NativeMusic.java 2KB
NativeMusicInfo2.java 2KB
NowPlay.java 1KB
NetworkMusic.java 295B
bg_lyc.jpg 76KB
player_background.png 118KB
player_background.png 103KB
icon.png 4KB
icon.png 4KB
icon.png 3KB
icon.png 2KB
icon.png 2KB
frame_player_normal.png 2KB
frame_player_normal.png 2KB
frame_player_press.png 2KB
frame_player_press.png 2KB
frame_internet_press.png 2KB
frame_internet_press.png 2KB
frame_internet_normal.png 2KB
frame_internet_normal.png 2KB
icon.png 2KB
title_background.png 1KB
title_background.png 1KB
frame_menu_normal.png 1KB
frame_menu_normal.png 1KB
frame_local_normal.png 929B
frame_local_press.png 929B
frame_local_normal.png 929B
frame_local_press.png 929B
lyrics_handle_shrink_press.png 502B
lyrics_handle_shrink_press.png 502B
lyrics_handle_bg.png 280B
lyrics_handle_bg.png 280B
lyrics_handle_shrink.png 127B
lyrics_handle_shrink.png 127B
lyrics_handle_expand.png 123B
lyrics_handle_expand.png 123B
.project 845B
project.properties 360B
default.properties 35B
music_main.xml 3KB
colors.xml 2KB
now_play.xml 1KB
AndroidManifest.xml 937B
native_music_info.xml 731B
native_music_info2.xml 577B
共 104 条
- 1
- 2
Tommy_sima
- 粉丝: 0
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页