• 团队冲刺第五天


    1、这次自己实现的是在地图进行运动轨迹的同时。得到运动的总距离。对于时间也可以获取到。但是速度方面有一点欠缺。还需要改进和增强。明天准备获取得到运动的每一部分的具体时间,得到速度。舒适速度和平均速度。今天变更的代码操作如下图所示;

    public String getDistance(LatLng start,LatLng end){
            double lat1 = (Math.PI/180)*start.latitude;
            double lat2 = (Math.PI/180)*end.latitude;
    
            double lon1 = (Math.PI/180)*start.longitude;
            double lon2 = (Math.PI/180)*end.longitude;
            Toast.makeText(DynamicDemo.this,String.valueOf(lat1), Toast.LENGTH_SHORT).show();
            Toast.makeText(DynamicDemo.this,String.valueOf(lon1), Toast.LENGTH_SHORT).show();
            Toast.makeText(DynamicDemo.this,String.valueOf(lat2), Toast.LENGTH_SHORT).show();
            Toast.makeText(DynamicDemo.this,String.valueOf(lon2), Toast.LENGTH_SHORT).show();
    
            //地球半径
            double R = 6371;
    
            //两点间距离 km,如果想要米的话,结果*1000
            double d =  Math.acos(Math.sin(lat1)*Math.sin(lat2)+Math.cos(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1))*R;
            if(d<1)
                return (int)d*1000+"m";
            else
                return String.format("%.2f",d)+"km";
        }

    2、今天完成了APP首页的设计,并且获取到登录者的信息,让其显示在用户基础信息的位置,包括头像和用户名。还有就是对闹钟功能的基本设计及思路,完成了添加闹钟的界面设计,明天再继续完成详细功能。下面是主要代码和截图

    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.home);
            muserOperator = new UserOperator(this);
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
            DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                    this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
            drawer.addDrawerListener(toggle);
            toggle.syncState();
            NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
            navigationView.setNavigationItemSelectedListener(this);
    //        LayoutInflater layoutInflater = this.getLayoutInflater();
    //        view =layoutInflater.inflate(R.layout.home_header,null);
    //        imageView=(ImageView)view.findViewById(R.id.userimageView);
    //        textView=(TextView) view.findViewById(R.id.usernameView);
            Intent intent = getIntent();//获取Intent对象
            String username = intent.getStringExtra("username");
            textView=navigationView.getHeaderView(0).findViewById(R.id.usernameView);
            imageView=navigationView.getHeaderView(0).findViewById(R.id.userimageView);
            User bean = muserOperator.isExit(username);
            String userpicture = bean.userpicture;
    
            //Log.d("volley", userpicture);
            textView.setText(username);
                Bitmap bitmap= BitmapFactory.decodeFile(userpicture);
    
                imageView.setImageBitmap(bitmap);
            fm = this.getSupportFragmentManager();
            switchFragment("首页");
        }

     3.今天继续昨天的内容,完成了音乐适配器的相关代码,增加了SD卡音乐信息的读取的学习和代码书写。并成功读取手机SD里面的歌曲信息。明天准备完成手机SD音乐的播放。

    package com.example.keeprunning6;
    
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.TextView;
    
    import java.util.ArrayList;
    
    public class LocalMusicAdapter extends BaseAdapter {
    
        private Context context;
        private LayoutInflater inflater;
        private ArrayList<LocalMusicBean>list;
    
        public LocalMusicAdapter(Context context,ArrayList<LocalMusicBean>list){
            this.context=context;
            this.list=list;
            this.inflater=LayoutInflater.from(context);
        }
        @Override
        public int getCount() {
            return list.size();
        }
    
        @Override
        public Object getItem(int position) {
            return list.get(position);
        }
    
        @Override
        public long getItemId(int position) {
            return position;
        }
    
        static class ViewHolder{
            public TextView music_num,music_song,music_singer,music_album,music_durtion;
    
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder viewHolder = null;
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.item_local_music, null);
                viewHolder = new ViewHolder();
                viewHolder.music_num = convertView.findViewById(R.id.item_local_music_num);
                viewHolder.music_song=convertView.findViewById(R.id.item_local_music_song);
                viewHolder.music_singer=convertView.findViewById(R.id.item_local_music_singer);
                viewHolder.music_album=convertView.findViewById(R.id.item_local_music_album);
                viewHolder.music_durtion=convertView.findViewById(R.id.item_local_music_durtion);
                convertView.setTag(viewHolder);
            }else{
                viewHolder=(ViewHolder)convertView.getTag();
            }
            LocalMusicBean bean=list.get(position);
            viewHolder.music_num.setText((position+1)+"");
            viewHolder.music_song.setText(bean.getSong());
            viewHolder.music_singer.setText(bean.getSinger());
            viewHolder.music_album.setText(bean.getAlbum());
            viewHolder.music_durtion.setText(bean.getDuration());
            return convertView;
        }
    }
    package com.example.keeprunning6;
    
    import android.Manifest;
    import android.content.ContentResolver;
    import android.content.pm.PackageManager;
    import android.database.Cursor;
    import android.net.Uri;
    import android.os.Bundle;
    import android.provider.MediaStore;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ListView;
    import android.widget.TextView;
    
    import androidx.appcompat.app.AppCompatActivity;
    import androidx.core.app.ActivityCompat;
    import androidx.core.content.ContextCompat;
    
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    
    public class MainActivity extends AppCompatActivity {
    
        //音乐列表试图
        private ListView listView;
        //音乐列表
        private ArrayList<LocalMusicBean> list=new ArrayList<>();
        //当前播放的音乐以及歌手
        private TextView now_music_song,now_music_singer,now_music_duration,now_music_ablum;
    
        private LocalMusicAdapter adapter;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
    
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            listView=findViewById(R.id.music_list);
            now_music_song=findViewById(R.id.local_music_botton_tv_song);
            now_music_singer=findViewById(R.id.item_local_music_singer);
    
            //自定义数据
    
            adapter=new LocalMusicAdapter(MainActivity.this,list);
            listView.setAdapter(adapter);
    
            //加载本地数据源
            localMusicData();
    
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    //上面的position参数是歌曲在列表中的索引
    
                    //播放选中的音乐
    
                    //切换下方当前音乐信息
                    now_music_song.setText(list.get(position).getSong());
                    now_music_singer.setText(list.get(position).getSinger());
    
                }
            });
    
        }
    
        private void localMusicData(){
            //加载本地存储当中的音乐mp3文件到集合当中
    
            //1.获取ContentResolver对象
            ContentResolver resolver=getContentResolver();
            //2.获取本地音乐存储的Uri地址
            Uri uri= MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            //3.开始查询地址
            Cursor cursor=resolver.query(uri,null,null,null,null);
            //4.遍历Cursor
            int id=0;
            while(cursor.moveToNext()){
                String song=cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
                String singer=cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
                String album=cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
                id++;
                //歌曲编号变成String类型
                String sid=String.valueOf(id);
                String path=cursor.getString(cursor.getColumnIndex((MediaStore.Audio.Media.DATA)));
               // String duration=cursor.getString(cursor.getColumnIndex((MediaStore.Audio.Media.DURATION)));
               int duration=cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
                SimpleDateFormat sdf=new SimpleDateFormat("mm:ss");
                String time = formatTime(duration);
    
                //将一行当中的数据封装到对象当中
                LocalMusicBean bean=new LocalMusicBean(sid,song,singer,album,time,path);
                list.add(bean);
    
            }
            //数据变化,提示适配器更新
            adapter.notifyDataSetChanged();
    
        }
    
        //    转换歌曲时间的格式
        public static String formatTime(int time) {
            if (time / 1000 % 60 < 10) {
                String tt = time / 1000 / 60 + ":0" + time / 1000 % 60;
                return tt;
            } else {
                String tt = time / 1000 / 60 + ":" + time / 1000 % 60;
                return tt;
            }
        }
    
    
    }
  • 相关阅读:
    webrtc系列之-像老鼠一样打洞
    Ubuntu记录用户IP访问操作信息工具
    OPENVIDU实现同一用户同时发布多个流媒体
    如何使用Nginx-rtmp搭建简易的HLS直播系统
    python实现数据库主从状态监控
    简单分析实现运维利器---批量操作bashshell
    《我与Windows Server 2008R2那点事儿》之域控账户故障事件
    常用动态路由协议之IS-IS
    在云服务器上搭建Python开发环境
    基于Python3接口自动化测试开发相关常用方法
  • 原文地址:https://www.cnblogs.com/yumazemadui/p/12733457.html
Copyright © 2020-2023  润新知