Android music player (3) carousel map

This is a simple music player project I made in my sophomore year last year: it was written as much as possible to imitate Kugou Music, and the specific functions are as follows:

1: Startup animation: Click to run the program and a two-second video will appear, similar to the startup animation of Kugou Music, very impressive!

2: Login registration interface: Enter the account number and password to check the information to log in!

3: Carousel: Exactly the same as Kugou Music, there is an automatic cycle carousel above the main interface, click on each picture information of the carousel to enter the corresponding specific service, very extra points!

4: The turntable of the music record, the progress bar of the song synchronization, and the pause/play/continue/switching of the music!

5: Music search is realized!

6: Play the video column!

7; The layout of the personal information interface is realized, such as feedback, rating, more, gender age nickname, collection, etc.!

The carousel code is as follows:

package com.ypc.xiaoxiongmusic;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;
import android.app.Fragment;

import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static android.view.View.VISIBLE;

@SuppressLint("ValidFragment")
public class musicFragment extends Fragment  {
    ListView lv;
    SearchView searchView;
    private ViewPager mViewPaper;
    private List<ImageView> images;
    private List<View> dots;
    private int currentItem;
    //记录上一次点的位置
    private int oldPosition = 0; 
    private ViewPagerAdapter adapter;
    //存放图片的id
    private int selectedPosition=0; 
    private ImageView bf; 
    private int[] imageIds = new int[]{ 
            R.drawable.lunchatu1, 
            R.drawable.lunchatu2, 
            R.drawable.lunchatu3, 
            R.drawable.lunchatu2, 
            R.drawable.lunchatu3 
    }; 
    //Store the title of the picture 
    private String[] titles = new String[]{ 
            "See you again, it's still you", 
            "I've been waiting for this day for a long time", 
            "Genius girl returns again", 
            "Imagine the music, click Brighten you and me", 
            "HELLO,DY.MEMORY" 
    }; 
    private TextView title; 
    private ScheduledExecutorService scheduledExecutorService; 
    private static List<Integer> sPics=new ArrayList<>(); 
    /// 
   * static { 
        sPics.add(R.drawable.b1); 
        sPics.add(R.drawable.b2 ) ); 
        sPics.add(R.drawable.b3); 
    }*/ 
    private ImageView m1,m2,m3,m4; 
    private View view; 
    public static String[] name={"Tae Yeon(태연) - 들리나요(Listen See you)", "Taeyeon(태연) - 제주도의푸른밤(Blue Night of Jeju Island)", "Taeyeon(태연) - 그리고하나(There is one more)","Taeyeon(태연) - Rescue Me "," Taeyeon (태연) - My Love (Duet Ver.)", "Hua Chenyu- I want to love this world so much (Live)", 
            "Hua Chenyu- Talk to the Children of Mars", "Hua Chenyu- The King and Beggar", "Hua Chenyu - Bullfighting (Live)", "Hua Chenyu - Dust in Fireworks", "Hua Chenyu - Madhouse (Live)", "Hua Chenyu- Travel Around", "Hua Chenyu- Search", "Hua Chenyu- Boring People", "Hua Chenyu- For Forever", "Hua Chenyu- Mayfly", "Hua Chenyu- We (Live)", "Hua Chenyu - heterogeneous", 
            "Hua Chenyu- I care about you", "Hua Chenyu- You have to believe that this is not the last day" ,"Hua Chenyu- Jackdaw Boy", "Hua Chenyu- Qi Tian", "Zhang Yixing- Will be fine", "Zhang Yixing- Good Night", "Zhang Yixing- Alone", "Zhang Yixing- Mask (Live)", "Zhang Yixing - grandmother","Zhang Yixing-I'm not good", "Zhang Yixing- Pray", "Taeyan(태연) - Gee (Busking Ver.)(Live)", "Taeyan(태연) - 만약에(If) (Busking Ver.) (Live)",
            "Tae Yeon (태연) - bad guy (Busking Ver.) (Live)", "Tae Yeon (태연) - 기억을걷는시간 (Time to Gather Memories) (Busking Ver.) (Live)", "Leslie Cheung - Strange You are too beautiful", "Leslie Cheung-left and right hands", "Leslie Cheung-at least you (00 Live) (live version)", "Leslie Cheung-me"};  
    public static int[] icons={R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R. drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx,R.drawable.musicx
            ,R.drawable.musicx,R.drawable.musicx,R .drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable .musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx 
            , R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx, R.drawable.musicx ,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx,R.drawable.musicx}; 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){

        View view = inflater.inflate(R.layout.fragment_music, container, false); 
        //lv.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, name)); 
        searchView =view. findViewById(R.id.sv);
        lv=view.findViewById(R.id.lv);
        lv.setTextFilterEnabled(true); 
        // Set the search text listener 
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { 
            // Trigger this method when the search button is clicked 
            @Override 
            public boolean onQueryTextSubmit(String query) { 
                return false; 
            } 
            // This method is triggered when the search content changes 
            @Override 
            public boolean onQueryTextChange(String newText) { 
                if (!TextUtils.isEmpty(newText)){ 
                    lv.setFilterText(newText); 
                }else{ 
                    lv.clearTextFilter(); 
                } 
                return false;
            }
        });
        bf=view.findViewById(R.id.bf);
        mViewPaper = (ViewPager)view. findViewById(R.id.vp);
        images = new ArrayList<ImageView>();
        for(int i = 0; i < imageIds.length; i++){
            ImageView imageView = new ImageView(getActivity());
            imageView.setBackgroundResource(imageIds[i]);
            images.add(imageView);
        }
        dots = new ArrayList<View>();
        dots.add(view.findViewById(R.id.dot_0));
        dots.add(view.findViewById(R.id.dot_1));
        dots.add(view.findViewById(R.id.dot_2));
        dots.add(view.findViewById(R.id.dot_3));
        dots.add(view.findViewById(R.id.dot_4));
        title = (TextView) view.findViewById(R.id.title);
        title.setText(titles[0]);
        adapter = new ViewPagerAdapter();
        mViewPaper.setAdapter(adapter);
        //论插图的ontauch点击方法
        mViewPaper.setOnTouchListener(new View.OnTouchListener() {
            int flage = 0 ;
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        flage = 0 ;
                        break ;
                    case MotionEvent.ACTION_MOVE:
                        flage = 1 ;
                        break ;
                    case  MotionEvent.ACTION_UP :
                        if (flage == 0) {
                            int item = mViewPaper.getCurrentItem();
                            if (item == 0) {
                                Intent intent = new Intent();
                                intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//此处填链接
                                intent.setData(content_url);
                                startActivity(intent);
                            } else if (item == 1) {
                                Intent intent = new Intent();
                                intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//此处填链接
                                intent.setData(content_url);
                                startActivity(intent);
                            } else if (item == 2) {
                                Intent intent = new Intent();
                                intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//Fill in the link here
                                intent.setData(content_url);
                                startActivity(intent);
                            }else if (item == 3) {
                                Intent intent = new Intent();
                                intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//此处填链接
                                intent.setData(content_url);
                                startActivity(intent);
                            } else if (item == 4) {
                                Intent intent = new Intent();
                                intent.setAction("android.intent.action.VIEW");
                                Uri content_url = Uri.parse("https://www.kuaishou.com/f/X-5hKhok9ebbLDq1");//此处填链接
                                intent.setData(content_url);
                                startActivity(intent);
                            }
                        }
                        break ;
                }
                return false;
            }
        });
        mViewPaper.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                title.setText(titles[position]);
                dots.get(position).setBackgroundResource(R.drawable.red);
                //Toast.makeText(getActivity(),"hurhurhghrui",Toast.LENGTH_SHORT).show();
                dots.get(oldPosition).setBackgroundResource(R.drawable.pure);
                oldPosition = position;
                currentItem = position;
            }
            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
            }
            @Override
            public void onPageScrollStateChanged(int arg0) {
            }
        });
        m1=view.findViewById(R.id.m1);
        m2=view.findViewById(R.id.m2);
        m3=view.findViewById(R.id.m3);
         m4=view.findViewById(R.id.m4);
        m1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent4=new Intent(getActivity(),tukuActivity.class);
                startActivity(intent4);
            }
        });
        m2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent5=new Intent(getActivity(),paihangbangActivity.class);
                startActivity(intent5);
            }
        });
        m3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent6=new Intent(getActivity(),fenleiActivity.class);
                startActivity(intent6);
            }
        });
        //ListView listView=view.findViewById(R.id.lv);
        MyBaseAdapter adapter=new MyBaseAdapter();
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent=new Intent(getActivity(),Music_Activity.class);//创建Intent对象,启动check
                //将数据存入Intent对象
                intent.putExtra("name",name[position]);
                intent.putExtra("position",String.valueOf(position));
                startActivity(intent);
               lv.setSelector(R.drawable.bf1);
            }
        });
        return view;
    }

    private class ViewPagerAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return images.size();
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }
        @Override
        public void destroyItem(ViewGroup view, int position, Object object) {
            // TODO Auto-generated method stub
            view.removeView(images.get(position));
        }
        @Override
        public Object instantiateItem(ViewGroup view, int position) {
            // TODO Auto-generated method stub
            view.addView(images.get(position));
            return images.get(position);
        }
    }
   /* @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }*/

    /**
     * 利用线程池定时执行动画轮播
     */
    @Override
    public void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); 
        scheduledExecutorService.scheduleWithFixedDelay( 
                new ViewPageTask(), 
                2, 
    private Handler mHandler = new Handler(){
                2,
                TimeUnit.SECONDS);
    } 
    /** 
     * Image carousel task 
     * @author liuyazhuang 
     * 
     */ 
    private class ViewPageTask implements Runnable{ 
        @Override 
        public void run() { 
            currentItem = (currentItem + 1) % imageIds.length; 
            mHandler.sendEmptyMessage(0); 
        } 
    } 
    /** 
     * Receive the data passed by the child thread 
     */ 
        public void handleMessage(android.os.Message msg) { 
            mViewPaper.setCurrentItem(currentItem); 
        }; 
    }; 
    @Override 
    public void onStop() { 
        // TODO Auto- generated method stub
        super.onStop();
        if(scheduledExecutorService != null){
            scheduledExecutorService.shutdown();
            scheduledExecutorService = null;
        }
    }
    class MyBaseAdapter extends BaseAdapter{
        @Override
        public int getCount(){return  name.length;}
        @Override
        public Object getItem(int i){return name[i];}
        @Override
        public long getItemId(int i){return i;}

        @Override
        public View getView(int i ,View convertView, ViewGroup parent) {
            View view=View.inflate(musicFragment.this.getActivity(),R.layout.item_layout,null);
            TextView tv_name=view.findViewById(R.id.item_name);
            ImageView iv=view.findViewById(R.id.iv);
            ImageView bf=view.findViewById(R.id.bf);
            tv_name.setText(name[i]);
            iv.setImageResource(icons[i]);
            return view;
        }
    }

}

The corresponding xml interface file code is as follows:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <SearchView
        android:id="@+id/sv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <androidx.viewpager.widget.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="213dp"></androidx.viewpager.widget.ViewPager>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="45dip"
        android:layout_gravity="bottom"
android:background="@drawable/pure"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="图片标题"
            android:textColor="#0C0C0C" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="3dip"
            android:orientation="horizontal" >

            <View
                android:id="@+id/dot_0"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>

            <View
                android:id="@+id/dot_1"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>
            <View
                android:id="@+id/dot_2"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>
            <View
                android:id="@+id/dot_3"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>
            <View
                android:id="@+id/dot_4"
                android:layout_width="5dip"
                android:layout_height="5dip"
                android:layout_marginLeft="2dip"
                android:layout_marginRight="2dip"
                android:background="#66BD0F32"/>

        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="83dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/m1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/ylu" />

        <ImageView
            android:layout_weight="1"
            android:id="@+id/m2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@drawable/phbang" />
        <ImageView
            android:layout_weight="1"
            android:id="@+id/m3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@drawable/flei" />
        <ImageView
            android:layout_weight="1"
            android:id="@+id/m4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:src="@drawable/cnxhuan" />

    </LinearLayout>
    <ListView
        android:background="@drawable/yybj1"
        android:id="@+id/lv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</LinearLayout>

The screenshot of the effect is as follows:

 

 

Guess you like

Origin blog.csdn.net/Abtxr/article/details/126856942