732003684

导航

sd卡文件列表

(在F:\java\l铃声设置\RingtonePro)

 //ListView监听设置
        mLib.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                String p = m_MyDatabaseAdapter.getPath(arg2+1);
                Log.i("ListView",p+" clicked");
                onStart(p);
                Toast.makeText( getApplicationContext (),"长按进行设置", Toast.LENGTH_SHORT ).show();
                
            }
        });
 //点击播放试听
    public void onStart(String p)
    {
            /*Uri path= Uri.parse(p);
             player.stop();
             player = MediaPlayer.create(this, path);
             player.start();*/
        if(prePath.equals(p)&&player.isPlaying())
        {
            player.stop();
        }
        else
        {
            Uri path= Uri.parse(p);
            prePath = p;
                player.stop();
                player = MediaPlayer.create(this, path);
            player.start();
        }
    }
//设置--铃声
    public void setMyRingtone(final String p)  
    {  
      player.stop();

      File sdfile = new File(p);
      Log.i("File",p)
//设置--提示音
    public void setMyNotification(final String p)  
    { 
      player.stop();

      File sdfile = new File(p);    
      ContentValues values = new ContentValues();  
      values.put(MediaStore.MediaColumns.DATA, sdfile.getAbsolutePath());  
      values.put(MediaStore.MediaColumns.TITLE, sdfile.getName());
      values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");   
      values.put(MediaStore.Audio.Media.IS_RINGTONE, false);  
      values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);  
      values.put(MediaStore.Audio.Media.IS_ALARM, false);  
      values.put(MediaStore.Audio.Media.IS_MUSIC, false);  
      
      Uri uri = MediaStore.Audio.Media.getContentUriForPath(sdfile.getAbsolutePath());
      Uri newUri = this.getContentResolver().insert(uri, values);
      
 
      RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION, newUri); 
      Toast.makeText( getApplicationContext (),R.string.setNotificationSucceed, Toast.LENGTH_SHORT ).show();
      System.out.println("setMyNOTIFICATION-------------");
    } 

 

aStore.MediaColumns.DATA, sdfile.getAbsolutePath());  
      values.put(MediaStore.MediaColumns.TITLE, sdfile.getName());
      values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");   
      values.put(MediaStore.Audio.Media.IS_RINGTONE, true);  
      values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);  
      values.put(MediaStore.Audio.Media.IS_ALARM, false);  
      values.put(MediaStore.Audio.Media.IS_MUSIC, false);  
      
      Uri uri = MediaStore.Audio.Media.getContentUriForPath(sdfile.getAbsolutePath());
      Uri newUri = this.getContentResolver().insert(uri, values);
      
 

      RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_RINGTONE, newUri);
      Toast.makeText( getApplicationContext (),R.string.setRingtoneSucceed, Toast.LENGTH_SHORT ).show();
      
      System.out.println("setMyRingtone()-------------");
    }  
//设置--闹铃音
    public void setMyAlarm(final String p)  
    {  
      player.stop();

      File sdfile = new File(p);    
      ContentValues values = new ContentValues();  
      values.put(MediaStore.MediaColumns.DATA, sdfile.getAbsolutePath());  
      values.put(MediaStore.MediaColumns.TITLE, sdfile.getName());
      values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");   
      values.put(MediaStore.Audio.Media.IS_RINGTONE, false);  
      values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);  
      values.put(MediaStore.Audio.Media.IS_ALARM, true);  
      values.put(MediaStore.Audio.Media.IS_MUSIC, false);  
      
      Uri uri = MediaStore.Audio.Media.getContentUriForPath(sdfile.getAbsolutePath());
      Uri newUri = this.getContentResolver().insert(uri, values);
      
 
      RingtoneManager.setActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM, newUri); 
      Toast.makeText( getApplicationContext (),R.string.setAlarmSucceed, Toast.LENGTH_SHORT ).show();
      System.out.println("setMyNOTIFICATION-------------");
    } 
//这里可以理解为设置ListActivity的源
    private void fill(File[] files)
    {
        //清空列表
        this.directoryEntries.clear();
        
        //如果不是根目录则添加上一级目录项
        if (this.currentDirectory.getParent() != null){
            this.directoryEntries.add(new InputFileListItem(getString(R.string.up_one_level),getString(R.string.none), getResources().getDrawable(R.drawable.uponelevel),true));
        }
            

        Drawable AudioIcon = getResources().getDrawable(R.drawable.audio);
        Drawable FolderIcon = getResources().getDrawable(R.drawable.folder);
        for (File currentFile : files)
        {
            //取得文件名
            String fileName = currentFile.getName();
            if(currentFile.isDirectory()){
                this.directoryEntries.add(new InputFileListItem(fileName,currentFile.getAbsolutePath(), FolderIcon,true));
            }
            else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingAudio))){//过滤掉音频文件以外的文件
                this.directoryEntries.add(new InputFileListItem(fileName,currentFile.getAbsolutePath(), AudioIcon,false));
            }
        }
        Collections.sort(this.directoryEntries);
        //创建Adapter
        listAdapter = new InputFileListAdapter(this,this.directoryEntries);
        //添加Adapter
        fileList.setAdapter(listAdapter);
    }
//通过文件名判断是什么类型的文件
    private boolean checkEndsWithInStringArray(String checkItsEnd, 
                    String[] fileEndings)
    {
        for(String aEnd : fileEndings)
        {
            if(checkItsEnd.endsWith(aEnd))
                return true;
        }
        return false;
    }

//全选
private void selectAllItem() {
        // TODO Auto-generated method stub
        for(int i=0;i<directoryEntries.size();i++){
            if(!directoryEntries.get(i).isFolder()){
                listAdapter.map.put(i, true);
            }
        }
        listAdapter.notifyDataSetChanged();
    }
//全不选
private void unselectAllItem() {
        // TODO Auto-generated method stub
        for(int i=0;i<directoryEntries.size();i++){
            if(!directoryEntries.get(i).isFolder()){
                listAdapter.map.put(i, false);
            }
        }
        listAdapter.notifyDataSetChanged();
    }
//取反
private void toggleAllItem() {
        // TODO Auto-generated method stub
        for(int i=0;i<directoryEntries.size();i++){
            if(!directoryEntries.get(i).isFolder()){
                listAdapter.map.put(i,!listAdapter.map.get(i) );
            }
        }
        listAdapter.notifyDataSetChanged();//更新Adapter
    }
//设置ListView被点击时的监听
        fileList.setOnItemClickListener(new OnItemClickListener(){

            public void onItemClick(AdapterView<?> l, View v, int position,
                    long id) {
                // TODO Auto-generated method stub
                String selectedFileString = directoryEntries.get(position).getName();
                
                if (selectedFileString.equals(getString(R.string.up_one_level)))
                {
                    //返回上一级目录
                    upOneLevel();
                }
                else
                {
                            
                    File clickedFile = null;
                    Log.i("InputFile", directoryEntries.get(position).getDir());
                    clickedFile = new File(directoryEntries.get(position).getDir());
                    if(directoryEntries.get(position).isFolder()){
                        browseTo(clickedFile);
                    }
                    else{
                        //设置CheckBox
                        CheckBox checkBox = (CheckBox) v.findViewById(R.id.multiple_checkbox);
                        //点击时将选中状态反置
                        checkBox.toggle();
                        //将选中状态加入map保存
                        listAdapter.map.put(position, checkBox.isChecked());
                    }

                }
                
            }
            
        });

 

posted on 2013-02-05 14:57  732003684  阅读(296)  评论(0编辑  收藏  举报