private void selectDone() {
    if (mFolderPathInDB != null && mFolderPathInDB.size() == 0) {
      Toast.makeText(this, R.string.no_folder, 500).show();
      return;
    }

    String[] path = new String[mFolderPathInDB.size()];
    for (int i = 0; i < path.length; i++) {
      path[i] = mFolderPathInDB.get(i);
    }
    String nowPlayingpath =
        MusicUtils.getSongPath(getApplicationContext(), MusicUtils.getCurrentAudioId());
    MusicUtils.updateFolderPath(this, path);
    finish();

    Intent intent = new Intent();
    intent.setClass(this, LibraryActivity.class);
    intent.putExtra("folder", true);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    if (nowPlayingpath != null
        && !mFolderPathInDB.contains(
            nowPlayingpath.substring(0, nowPlayingpath.lastIndexOf("/")))) {
      Intent filterIntent = new Intent(MusicUtils.ACTION_FILTER);
      sendBroadcast(filterIntent);
    }
  }
  private void setAdapter() {
    mPathList = MusicUtils.getPathList(this);
    String[] folderPathinDB = MusicUtils.getFolderPath(this);

    mFolderPathInDB.clear();
    if (mPathList != null && folderPathinDB != null) {
      if (folderPathinDB.length > 0) {
        for (int i = 0; i < folderPathinDB.length; i++) {
          if (mPathList.contains(folderPathinDB[i])) {
            mFolderPathInDB.add(folderPathinDB[i]);
          } else {
            MusicUtils.deleteFolderPath(getApplicationContext(), folderPathinDB[i]);
          }
        }
      } else {
        for (int i = 0; i < mPathList.size(); i++) {
          mFolderPathInDB.add(mPathList.get(i));
        }
      }

      mAdapter =
          new MusicFolderAdapter(
              this, mPathList, mFolderPathInDB, mIsOuter, getApplicationContext());
      if (mAdapter != null) {
        mList.setAdapter(mAdapter);
        mList.setOnItemClickListener(SelectFolderActivity.this);
      }
    }
  }
        @Override
        public void handleMessage(Message msg) {
          if (msg.what == 1) {
            mAdapter =
                new MusicFolderAdapter(
                    SelectFolderActivity.this,
                    mPathList,
                    mFolderPathInDB,
                    2,
                    getApplicationContext());
          } else {
            mPathList = MusicUtils.getPathList(SelectFolderActivity.this);
            String[] folderPathinDB = MusicUtils.getFolderPath(SelectFolderActivity.this);
            if (mFolderPathInDB != null && mFolderPathInDB.size() != 0) {
              mFolderPathInDB.clear();
            }

            if (mPathList != null && folderPathinDB != null) {

              if (folderPathinDB.length > 0) {
                for (int i = 0; i < folderPathinDB.length; i++) {
                  mFolderPathInDB.add(folderPathinDB[i]);
                }
              } else {
                for (int i = 0; i < mPathList.size(); i++) {
                  mFolderPathInDB.add(mPathList.get(i));
                }
              }

              mAdapter =
                  new MusicFolderAdapter(
                      SelectFolderActivity.this,
                      mPathList,
                      mFolderPathInDB,
                      mIsOuter,
                      getApplicationContext());
            }
          }
          if (mAdapter != null) {
            mList.setAdapter(mAdapter);
            mAdapter.notifyDataSetChanged();
          }
          setupNoSongsView();
          if (MusicUtils.sService != null && Artistactionbar != null) {
            Artistactionbar.setMediaService(MusicUtils.sService);
          }
        }
 public void onItemCheckedStateChanged(ActionMode mode, int arg1, long arg2, boolean arg3) {
   int count = mFolderPathInDB.size();
   MusicUtils.updateActionModeTitle(mode, mContext, count);
   Log.i(TAG, "onItemCheckedStateChanged");
   if (isSelectAll()) {
     mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_clear_select);
   } else {
     mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_select_all);
   }
 }
 //    private class ModeCallback implements ListView.MultiChoiceModeListener{
 //    	private Context mContext;
 //    	public ModeCallback(Context context){
 //    		mContext=context;
 //    	}
 //		@Override
 //		public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
 //			// TODO Auto-generated method stub
 //			switch (item.getItemId()) {
 //			case lewa.R.id.action_mode_right_button:
 //				if(isSelectAll()){
 //					//mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_select_all);
 //					unselectAll();
 //				}else{
 //                    		//mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_clear_select);
 //                    		selectAll();
 //				}
 //				MusicUtils.updateActionModeTitle(mode, mContext, mFolderPathInDB.size());
 //				break;
 //			case R.id.action_done:
 //				selectDone();
 //				break;
 //			}
 //			return true;
 //		}
 //
 //		@Override
 //		public boolean onCreateActionMode(ActionMode mode, Menu menu) {
 //			// TODO Auto-generated method stub
 //			//mode.setRightActionButtonVisibility(View.VISIBLE);
 //                    if(isSelectAll()) {
 //			    //mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_clear_select);
 //                    } else {
 //                        //mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_select_all);
 //                    }
 //			int count=mFolderPathInDB.size();
 //			MusicUtils.updateActionModeTitle(mode, mContext, count);
 //			MenuInflater inflater=((ActionBarActivity) mContext).getMenuInflater();
 //                    inflater.inflate(R.menu.operation_menu, menu);
 //			return true;
 //		}
 //
 //		@Override
 //		public void onDestroyActionMode(ActionMode arg0) {
 //			// TODO Auto-generated method stub
 //			finish();
 //		}
 //
 //		@Override
 //		public boolean onPrepareActionMode(ActionMode arg0, Menu arg1) {
 //			// TODO Auto-generated method stub
 //			return false;
 //		}
 //
 //		@Override
 //		public void onItemCheckedStateChanged(ActionMode mode, int arg1,
 //				long arg2, boolean arg3) {
 //			int count=mFolderPathInDB.size();
 //			MusicUtils.updateActionModeTitle(mode, mContext, count);
 //                    Log.i(TAG, "onItemCheckedStateChanged");
 //                    if(isSelectAll()) {
 //			    //mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_clear_select);
 //                    } else {
 //                        //mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_select_all);
 //                    }
 //		}
 //
 //    }
 // pr938097 modify by wjhu end
 public void updateActionModeTitle() {
   if (mActionMode != null) {
     MusicUtils.updateActionModeTitle(
         mActionMode, getApplicationContext(), mFolderPathInDB.size());
     if (isSelectAll()) {
       mActionMode.setRightActionButtonResource(lewa.R.drawable.ic_menu_clear_select);
     } else {
       mActionMode.setRightActionButtonResource(lewa.R.drawable.ic_menu_select_all);
     }
   }
 }
 @Override
 public void onReceive(Context context, Intent intent) {
   String action = intent.getAction();
   if (Intent.ACTION_MEDIA_SCANNER_STARTED.equals(action)
       || Intent.ACTION_MEDIA_SCANNER_FINISHED.equals(action)) {
     MusicUtils.setSpinnerState(SelectFolderActivity.this);
     mReScanHandler.sendEmptyMessage(0);
   }
   if (Intent.ACTION_MEDIA_UNMOUNTED.equals(action)) {
     mReScanHandler.sendEmptyMessage(1);
   }
 }
 @Override
 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
   // TODO Auto-generated method stub
   mode.setRightActionButtonVisibility(View.VISIBLE);
   if (isSelectAll()) {
     mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_clear_select);
   } else {
     mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_select_all);
   }
   int count = mFolderPathInDB.size();
   MusicUtils.updateActionModeTitle(mode, mContext, count);
   MenuInflater inflater = ((ActionBarActivity) mContext).getMenuInflater();
   inflater.inflate(R.menu.operation_menu, menu);
   return true;
 }
 @Override
 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
   // TODO Auto-generated method stub
   switch (item.getItemId()) {
     case lewa.support.v7.appcompat.R.id.action_mode_right_button:
       if (isSelectAll()) {
         mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_select_all);
         unselectAll();
       } else {
         mode.setRightActionButtonResource(lewa.R.drawable.ic_menu_clear_select);
         selectAll();
       }
       MusicUtils.updateActionModeTitle(mode, mContext, mFolderPathInDB.size());
       break;
     case R.id.action_done:
       selectDone();
       break;
   }
   return true;
 }