功能分类:影音
支持平台:Android
运行环境:Android
开发语言:Java
开发工具:Eclipse
源码大小:7.88M
源码简介
学习使用的音乐播放器,登陆密码是123,。
源码运行截图
源码片段
package com.xue.Mp3Player;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ExpandableListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import com.xue.Mp3Player.R;
import com.xue.Mp3Player.Utils.DataUtils;
import com.xue.Mp3Player.Utils.MyApplication;
import com.xue.Mp3Player.Utils.PlayUtils;
public class MyMusicListActivity extends ExpandableListActivity {
private ExpandableListView myMusicListView;
private ArrayList<hashmap<string, object="">> groupsList;
private List<list<hashmap<string, object="">>> childsList;
public static MyMusicListAdapter listAdapter;
private static Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mymusic_list_layout);
myMusicListView = getExpandableListView();
context = this;
groupsList = new ArrayList<hashmap<string, object="">>();
HashMap<string, object=""> group1 = new HashMap<string, object="">();
group1.put("name", "旧城");
HashMap<string, object=""> group2 = new HashMap<string, object="">();
group2.put("name", "旧梦");
HashMap<string, object=""> group3 = new HashMap<string, object="">();
group3.put("name", "旧人");//设置收藏类别
groupsList.add(group1);
groupsList.add(group2);
groupsList.add(group3);
childsList = new ArrayList<list<hashmap<string, object="">>>();
childsList.add(MyApplication.getHappyMusicList());
childsList.add(MyApplication.getQuietMusicList());
childsList.add(MyApplication.getSadMusicList());
listAdapter = new MyMusicListAdapter(this, groupsList, childsList);
myMusicListView.setAdapter(listAdapter);
}
public static Context getContext(){
return context;
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
HashMap<string, object=""> map = childsList.get(groupPosition).get(childPosition);
if (map.get("name").equals(PlayService.name) && MyApplication.playStatus == 1) {
Toast.makeText(context, "正在播放...", 0).show();
}else {
boolean b = PlayUtils.addMusicToList(context, map, MyApplication.getPlayMusicList());
if (b) {
PlayMusicListActivity.myListAdapter.notifyDataSetChanged();
PlayUtils.turnToPlay(map, context);
}
}
return super.onChildClick(parent, v, groupPosition, childPosition, id);
}
public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
backDialog();
}
return false;
};
@Override
protected void onDestroy() {
DataUtils.upData_allLists();
super.onDestroy();
}
public void backDialog() {
AlertDialog.Builder builder = new Builder(this);
builder.setMessage("确认退出吗?");
builder.setTitle("提示");
builder.setPositiveButton("确认", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) context).finish();
new AsyncTask<void, void,="" void="">(){
@Override
protected Void doInBackground(Void... params) {
if (MyApplication.playStatus != 0) {
PlayService.stop();
// PlayService.player.release();
}
DataUtils.upData_allLists();
return null;
}
}.execute();
}
});
builder.setNegativeButton("取消", new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
class MyMusicListAdapter extends BaseExpandableListAdapter {
private Context context;
private List<hashmap<string, object="">> groups;
private List<list<hashmap<string, object="">>> childs;
private childViewsHolder childHolder;
private GroupViewsHolder groupHolder;
public MyMusicListAdapter(Context context, List<hashmap<string, object="">> groups, List<list<hashmap<string, object="">>> childs) {
this.context = context;
this.groups = groups;
this.childs = childs;
}
private class childViewsHolder {
TextView childText;
ImageButton childButton;
}
public Object getChild(int arg0, int arg1) {
return childs.get(arg0).get(arg1);
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public void removeChildItem(int groupPosition, int childPosition) {
childs.get(groupPosition).remove(childPosition);
this.notifyDataSetChanged();
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView != null) {
childHolder = (childViewsHolder) convertView.getTag();
} else {
childHolder = new childViewsHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.mymusic_childs_layout, null);
childHolder.childText = (TextView) convertView.findViewById(R.id.text_childItem);
childHolder.childButton = (ImageButton) convertView.findViewById(R.id.button_deleteChildItem);
convertView.setTag(childHolder);
}
HashMap<string, object=""> childItem = childs.get(groupPosition).get(childPosition);
if (childItem != null) {
String name = (String) childItem.get("name");
childHolder.childText.setText(name);
childHolder.childButton.setOnClickListener(new childItemOnClick(groupPosition, childPosition));
}
return convertView;
}
public class childItemOnClick implements android.view.View.OnClickListener {
private int groupPosition;
private int childPosition;
public childItemOnClick(int groupPosition, int childposition) {
this.groupPosition = groupPosition;
this.childPosition = childposition;
}
public void onClick(View v) {
removeChildItem(groupPosition, childPosition);
}
}
public int getChildrenCount(int groupPosition) {
return childs.get(groupPosition).size();
}
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
public int getGroupCount() {
return groups.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
private class GroupViewsHolder {
TextView groupText;
ImageButton groupButton;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
if (convertView != null) {
groupHolder = (GroupViewsHolder) convertView.getTag();
} else {
groupHolder = new GroupViewsHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.mymusic_groups_layout, null);
groupHolder.groupText = (TextView) convertView.findViewById(R.id.text_groupItem);
groupHolder.groupButton = (ImageButton) convertView.findViewById(R.id.button_playAll);
convertView.setTag(groupHolder);
}
HashMap<string, object=""> map = groups.get(groupPosition);
if (map != null) {
String name = (String) map.get("name");
groupHolder.groupText.setText(name);
groupHolder.groupButton.setOnClickListener(new GroupOnClick(groupPosition));
}
return convertView;
}
class GroupOnClick implements View.OnClickListener {
private int position;
public GroupOnClick(int position) {
this.position = position;
}
public void onClick(View v) {
switch (position) {
case 0:
PlayUtils.turnToPlay_List(context, MyApplication.getHappyMusicList());
break;
case 1:
PlayUtils.turnToPlay_List(context, MyApplication.getQuietMusicList());
break;
case 2:
PlayUtils.turnToPlay_List(context, MyApplication.getSadMusicList());
break;
default:
break;
}
}
}
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}
}
</string,></string,></list<hashmap<string,></hashmap<string,></list<hashmap<string,></hashmap<string,></void,></string,></list<hashmap<string,></string,></string,></string,></string,></string,></string,></hashmap<string,></list<hashmap<string,></hashmap<string,>
- 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.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
- 208.
- 209.
- 210.
- 211.
- 212.
- 213.
- 214.
- 215.
- 216.
- 217.
- 218.
- 219.
- 220.
- 221.
- 222.
- 223.
- 224.
- 225.
- 226.
- 227.
- 228.
- 229.
- 230.
- 231.
- 232.
- 233.
- 234.
- 235.
- 236.
- 237.
- 238.
- 239.
- 240.
- 241.
- 242.
- 243.
- 244.
- 245.
- 246.
- 247.
- 248.
- 249.
- 250.
- 251.
- 252.
- 253.
- 254.
- 255.
- 256.
- 257.
- 258.
- 259.
- 260.
- 261.
- 262.
- 263.
- 264.
- 265.
- 266.
- 267.
- 268.
- 269.
- 270.
- 271.
- 272.
- 273.
- 274.
- 275.
- 276.
- 277.
- 278.
- 279.
- 280.
- 281.
- 282.
- 283.
- 284.
- 285.
- 286.
- 287.
- 288.
- 289.
- 290.
- 291.
- 292.
- 293.
- 294.
- 295.
- 296.
- 297.