@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo info) { super.onCreateContextMenu(menu, v, info); boolean multi_data = handler.hasMultiSelectData(); AdapterContextMenuInfo _info = (AdapterContextMenuInfo) info; selected_list_item = handler.getData(_info.position); if (flmg.isDirectory(selected_list_item)) { menu.setHeaderTitle("Folder operations"); menu.add(0, D_MENU_DELETE, 0, "Delete Folder"); menu.add(0, D_MENU_RENAME, 0, "Rename Folder"); menu.add(0, D_MENU_COPY, 0, "Copy Folder"); menu.add(0, D_MENU_ZIP, 0, "Zip Folder"); menu.add(0, D_MENU_PASTE, 0, "Paste into folder").setEnabled(holding_file || multi_data); menu.add(0, D_MENU_UNZIP, 0, "Extract here").setEnabled(holding_zip); } else { menu.setHeaderTitle("File Operations"); menu.add(0, F_MENU_DELETE, 0, "Delete File"); menu.add(0, F_MENU_RENAME, 0, "Rename File"); menu.add(0, F_MENU_COPY, 0, "Copy File"); menu.add(0, F_MENU_ATTACH, 0, "Email File"); } }
@Override public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case D_MENU_DELETE: case F_MENU_DELETE: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Warning "); builder.setIcon(R.drawable.warning); builder.setMessage( "Deleting " + selected_list_item + " cannot be undone. Are you sure you want to delete?"); builder.setCancelable(false); builder.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setPositiveButton( "Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { handler.deleteFile(flmg.getCurrentDir() + "/" + selected_list_item); } }); AlertDialog alert_d = builder.create(); alert_d.show(); return true; case D_MENU_RENAME: showDialog(D_MENU_RENAME); return true; case F_MENU_RENAME: showDialog(F_MENU_RENAME); return true; case F_MENU_ATTACH: File file = new File(flmg.getCurrentDir() + "/" + selected_list_item); Intent mail_int = new Intent(); mail_int.setAction(android.content.Intent.ACTION_SEND); mail_int.setType("application/mail"); mail_int.putExtra(Intent.EXTRA_BCC, ""); mail_int.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); startActivity(mail_int); return true; case F_MENU_COPY: case D_MENU_COPY: copied_target = flmg.getCurrentDir() + "/" + selected_list_item; holding_file = true; detail_label.setText("Waiting to paste file " + selected_list_item); return true; case D_MENU_PASTE: boolean multi_select = handler.hasMultiSelectData(); if (multi_select) { handler.copyFileMultiSelect(flmg.getCurrentDir() + "/" + selected_list_item); } else if (holding_file && copied_target.length() > 1) { handler.copyFile(copied_target, flmg.getCurrentDir() + "/" + selected_list_item); holding_file = false; detail_label.setText(""); } return true; case D_MENU_ZIP: String dir = flmg.getCurrentDir(); handler.zipFile(dir + "/" + selected_list_item); return true; case D_MENU_UNZIP: if (holding_zip && zipped_target.length() > 1) { String current_dir = flmg.getCurrentDir() + "/" + selected_list_item + "/"; String old_dir = zipped_target.substring(0, zipped_target.lastIndexOf("/")); String name = zipped_target.substring(zipped_target.lastIndexOf("/") + 1, zipped_target.length()); if (new File(zipped_target).canRead() && new File(current_dir).canWrite()) { handler.unZipFileToDir(name, current_dir, old_dir); path_label.setText(current_dir); } else { Toast.makeText(this, "You do not have permission to unzip " + name, Toast.LENGTH_SHORT) .show(); } } holding_zip = false; detail_label.setText(""); zipped_target = ""; return true; } return false; }