public EventHandler( Context context, FileOperateCallbacks callbacks, final FileManager manager, final CatalogList CataList) { mContext = context; mFileMang = manager; mCataList = CataList; mCallbacks = callbacks; mDataSource = new ArrayList<String>(mFileMang.getHomeDir(FileManager.ROOT_FLASH)); }
/** This method, handles the button presses of the top buttons found in the Main activity. */ @Override public void onClick(View v) { switch (v.getId()) { case R.id.home_sdcard_button: mFileMang.canMkdir = true; refreshFocus(preView, v); if (mFileMang.whichRoot() == FileManager.ROOT_SDCARD && mlistmode == TREEVIEW_MODE) { break; } mlistmode = TREEVIEW_MODE; if (multi_select_flag) { mDelegate.killMultiSelect(true); mFileMang.mHoldingFile = false; mFileMang.mAllowSelectAll = false; mInfoLabel.setText(""); mFileMang.moveOrCopyFile = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.Multi_select_off), Toast.LENGTH_SHORT) .show(); } updateDirectory(mFileMang.getHomeDir(FileManager.ROOT_SDCARD)); if (mPathLabel != null) mPathLabel.setText( mFileMang.getCurrentDir().substring(5, mFileMang.getCurrentDir().length())); break; case R.id.home_usbhost_button: mFileMang.canMkdir = true; refreshFocus(preView, v); if (mFileMang.whichRoot() == FileManager.ROOT_USBHOST && mlistmode == TREEVIEW_MODE) { break; } mlistmode = TREEVIEW_MODE; if (multi_select_flag) { mDelegate.killMultiSelect(true); mFileMang.mHoldingFile = false; mFileMang.mAllowSelectAll = false; mInfoLabel.setText(""); mFileMang.moveOrCopyFile = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.Multi_select_off), Toast.LENGTH_SHORT) .show(); } updateDirectory(mFileMang.getHomeDir(FileManager.ROOT_USBHOST)); if (mPathLabel != null) mPathLabel.setText( mFileMang.getCurrentDir().substring(5, mFileMang.getCurrentDir().length())); break; case R.id.home_flash_button: mFileMang.canMkdir = true; refreshFocus(preView, v); if (mFileMang.whichRoot() == FileManager.ROOT_FLASH && mlistmode == TREEVIEW_MODE) { break; } mlistmode = TREEVIEW_MODE; if (multi_select_flag) { mDelegate.killMultiSelect(true); mFileMang.mHoldingFile = false; mFileMang.mAllowSelectAll = false; mInfoLabel.setText(""); mFileMang.moveOrCopyFile = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.Multi_select_off), Toast.LENGTH_SHORT) .show(); } updateDirectory(mFileMang.getHomeDir(FileManager.ROOT_FLASH)); if (mPathLabel != null) mPathLabel.setText( mFileMang.getCurrentDir().substring(5, mFileMang.getCurrentDir().length())); break; case R.id.music_button: mFileMang.canMkdir = false; mlistmode = CATALOG_MODE; if (multi_select_flag) { mDelegate.killMultiSelect(true); mFileMang.mHoldingFile = false; mFileMang.mAllowSelectAll = false; mInfoLabel.setText(""); mFileMang.moveOrCopyFile = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.Multi_select_off), Toast.LENGTH_SHORT) .show(); } setFileList(mCataList.SetFileTyp(CatalogList.TYPE_MUSIC)); if (mPathLabel != null) mPathLabel.setText(mContext.getResources().getString(R.string.music)); refreshFocus(preView, v); break; case R.id.image_button: mFileMang.canMkdir = false; mlistmode = CATALOG_MODE; if (multi_select_flag) { mDelegate.killMultiSelect(true); mFileMang.mHoldingFile = false; mFileMang.mAllowSelectAll = false; mInfoLabel.setText(""); mFileMang.moveOrCopyFile = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.Multi_select_off), Toast.LENGTH_SHORT) .show(); } setFileList(mCataList.SetFileTyp(CatalogList.TYPE_PICTURE)); if (mPathLabel != null) mPathLabel.setText(mContext.getResources().getString(R.string.picture)); refreshFocus(preView, v); break; case R.id.movie_button: mFileMang.canMkdir = false; mlistmode = CATALOG_MODE; if (multi_select_flag) { mDelegate.killMultiSelect(true); mFileMang.mHoldingFile = false; mFileMang.mAllowSelectAll = false; mInfoLabel.setText(""); mFileMang.moveOrCopyFile = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.Multi_select_off), Toast.LENGTH_SHORT) .show(); } setFileList(mCataList.SetFileTyp(CatalogList.TYPE_MOVIE)); if (mPathLabel != null) mPathLabel.setText(mContext.getResources().getString(R.string.movie)); refreshFocus(preView, v); break; case R.id.ebook_button: mFileMang.canMkdir = false; mlistmode = CATALOG_MODE; if (multi_select_flag) { mDelegate.killMultiSelect(true); mFileMang.mHoldingFile = false; mFileMang.mAllowSelectAll = false; mInfoLabel.setText(""); mFileMang.moveOrCopyFile = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.Multi_select_off), Toast.LENGTH_SHORT) .show(); } setFileList(mCataList.SetFileTyp(CatalogList.TYPE_EBOOK)); if (mPathLabel != null) mPathLabel.setText(mContext.getResources().getString(R.string.ebook)); refreshFocus(preView, v); break; case R.id.apk_button: mFileMang.canMkdir = false; mlistmode = CATALOG_MODE; if (multi_select_flag) { mDelegate.killMultiSelect(true); mFileMang.mHoldingFile = false; mFileMang.mAllowSelectAll = false; mInfoLabel.setText(""); mFileMang.moveOrCopyFile = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.Multi_select_off), Toast.LENGTH_SHORT) .show(); } setFileList(mCataList.SetFileTyp(CatalogList.TYPE_APK)); if (mPathLabel != null) mPathLabel.setText(mContext.getResources().getString(R.string.apk)); refreshFocus(preView, v); break; case R.id.hidden_move: case R.id.hidden_copy: if (mMultiSelectData == null || mMultiSelectData.isEmpty()) { mDelegate.killMultiSelect(true); mFileMang.moveOrCopyFile = false; mFileMang.mAllowSelectAll = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.no_select), Toast.LENGTH_SHORT) .show(); break; } mFileMang.mCopyOrMoveSize = 0; for (String s : mMultiSelectData) { System.out.println("--->" + s); mFileMang.mCopyOrMoveSize += mFileMang.getDirOrFileSize(s); } if (v.getId() == R.id.hidden_move) delete_after_copy = true; mInfoLabel.setText( mContext.getResources().getString(R.string.Holding) + " " + mMultiSelectData.size() + " " + mContext.getResources().getString(R.string.files)); mFileMang.mHoldingFile = true; mFileMang.mAllowSelectAll = false; mDelegate.killMultiSelect(false); break; case R.id.hidden_delete: /* check if user selected objects before going further */ if (!mFileMang.moveOrCopyFile) { mMultiSelectData = null; } if (mMultiSelectData == null || mMultiSelectData.isEmpty()) { mDelegate.killMultiSelect(true); mFileMang.moveOrCopyFile = false; mFileMang.mAllowSelectAll = false; Toast.makeText( mContext, mContext.getResources().getString(R.string.no_select), Toast.LENGTH_SHORT) .show(); break; } final String[] data = new String[mMultiSelectData.size()]; int at = 0; for (String string : mMultiSelectData) data[at++] = string; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage( mContext.getResources().getString(R.string.delete_msg1) + " " + data.length + " " + mContext.getResources().getString(R.string.delete_msg2)); builder.setCancelable(false); builder.setPositiveButton( mContext.getResources().getString(R.string.Delete), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new BackgroundWork(DELETE_TYPE).execute(data); mDelegate.killMultiSelect(true); mFileMang.moveOrCopyFile = false; mFileMang.mAllowSelectAll = false; } }); builder.setNegativeButton( mContext.getResources().getString(R.string.Cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mDelegate.killMultiSelect(true); mFileMang.moveOrCopyFile = false; mFileMang.mAllowSelectAll = false; dialog.cancel(); } }); builder.create().show(); break; } }