@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); SharedPreferences.Editor editor = settings.edit(); boolean check; int color; /* resultCode must equal RESULT_CANCELED because the only way * out of that activity is pressing the back button on the phone * this publishes a canceled result code not an ok result code */ if (requestCode == SETTING_REQ && resultCode == RESULT_CANCELED) { // save the information we get from settings activity check = data.getBooleanExtra("HIDDEN", false); color = data.getIntExtra("COLOR", -1); editor.putBoolean(PREFS_HIDDEN, check); editor.putInt(PREFS_COLOR, color); editor.commit(); flmg.setShowHiddenFiles(check); handler.setTextColor(color); handler.updateDirectory(flmg.getNextDir(flmg.getCurrentDir(), true)); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home || item.getItemId() == 0) { return false; } mSettings.edit().putInt(PREFS_SORT, item.getItemId()).commit(); mFileMag.setSortType(item.getItemId()); mHandler.updateDirectory(mFileMag.getNextDir(mFileMag.getCurrentDir(), true)); return true; }
@Override public void onListItemClick(ListView parent, View view, int position, long id) { final String item = mHandler.getData(position); final File file = new File(mFileMag.getCurrentDir() + "/" + item); String item_ext = null; try { item_ext = item.substring(item.lastIndexOf(".") + 1, item.length()); } catch (IndexOutOfBoundsException e) { item_ext = ""; } if (file.isDirectory()) { if (file.canRead()) { mHandler.updateDirectory(mFileMag.getNextDir(item, false)); mPathLabel.setText(mFileMag.getCurrentDir()); if (!mUseBackKey) mUseBackKey = true; } else { Toast.makeText(this, R.string.permission, Toast.LENGTH_SHORT).show(); } } else if (item_ext.equalsIgnoreCase("zip")) { AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(R.string.alert); builder.setMessage(R.string.sure_this_directory); builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(mContext, file.getPath(), Toast.LENGTH_SHORT).show(); UnzipNotificationCenter unzipNotificationCenter = new UnzipNotificationCenter(mContext, FileImportActivity.class); int id = unzipNotificationCenter.prepareUnzipNotification( R.drawable.unzip, R.string.start_unzip, R.string.start_unzip, R.string.unzip_tip); unzipNotificationCenter.startUnzip( id, file.getPath(), Environment.getExternalStorageDirectory() + "/" + Constants.SAVE_DIRECTORY, true); } }); builder.setNegativeButton( R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }
/** * To add more functionality and let the user interact with more file types, this is the function * to add the ability. * * <p>(note): this method can be done more efficiently */ @Override public void onListItemClick(ListView parent, View view, int position, long id) { final String item = handler.getData(position); boolean multiSelect = handler.isMultiSelected(); File file = new File(flmg.getCurrentDir() + "/" + item); String item_ext = null; try { item_ext = item.substring(item.lastIndexOf("."), item.length()); } catch (IndexOutOfBoundsException e) { item_ext = ""; } /* * If the user has multi-select on, we just need to record the file * not make an intent for it. */ if (multiSelect) { table.addMultiPosition(position, file.getPath()); } else { if (file.isDirectory()) { if (file.canRead()) { handler.updateDirectory(flmg.getNextDir(item, false)); path_label.setText(flmg.getCurrentDir()); /*set back button switch to true (this will be better implemented later)*/ if (!use_back_key) use_back_key = true; } else Toast.makeText(this, "Can't read folder due to permissions", Toast.LENGTH_SHORT).show(); } /*music file selected--add more audio formats*/ else if (item_ext.equalsIgnoreCase(".mp3") || item_ext.equalsIgnoreCase(".m4a")) { Intent music_int = new Intent(this, AudioPlayblack.class); music_int.putExtra("MUSIC PATH", flmg.getCurrentDir() + "/" + item); startActivity(music_int); } /*photo file selected*/ else if (item_ext.equalsIgnoreCase(".jpeg") || item_ext.equalsIgnoreCase(".jpg") || item_ext.equalsIgnoreCase(".png") || item_ext.equalsIgnoreCase(".gif") || item_ext.equalsIgnoreCase(".tiff")) { if (file.exists()) { Intent pic_int = new Intent(); pic_int.setAction(android.content.Intent.ACTION_VIEW); pic_int.setDataAndType(Uri.fromFile(file), "image/*"); startActivity(pic_int); } } /*video file selected--add more video formats*/ else if (item_ext.equalsIgnoreCase(".m4v") || item_ext.equalsIgnoreCase(".3gp") || item_ext.equalsIgnoreCase(".wmv") || item_ext.equalsIgnoreCase(".mp4") || item_ext.equalsIgnoreCase(".ogg")) { if (file.exists()) { Intent movie_int = new Intent(); movie_int.setAction(android.content.Intent.ACTION_VIEW); movie_int.setDataAndType(Uri.fromFile(file), "video/*"); startActivity(movie_int); } } /*zip and gzip file selected (gzip will be implemented soon)*/ else if (item_ext.equalsIgnoreCase(".zip")) { // || item_ext.equalsIgnoreCase(".gzip")) { AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog alert; zipped_target = flmg.getCurrentDir() + "/" + item; CharSequence[] option = {"Extract here", "Extract to..."}; builder.setTitle("Extract"); builder.setItems( option, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: String dir = flmg.getCurrentDir(); handler.unZipFile(item, dir + "/"); break; case 1: detail_label.setText("Holding " + item + " to extract"); holding_zip = true; break; } } }); alert = builder.create(); alert.show(); } /*pdf file selected*/ else if (item_ext.equalsIgnoreCase(".pdf")) { if (file.exists()) { Intent file_int = new Intent(); file_int.setAction(android.content.Intent.ACTION_VIEW); file_int.setDataAndType(Uri.fromFile(file), "application/pdf"); startActivity(file_int); } } /*Android application file*/ else if (item_ext.equalsIgnoreCase(".apk")) { if (file.exists()) { Intent apk_int = new Intent(); apk_int.setAction(android.content.Intent.ACTION_VIEW); apk_int.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); startActivity(apk_int); } } /* HTML file */ else if (item_ext.equalsIgnoreCase(".html")) { if (file.exists()) { Intent html_int = new Intent(); html_int.setAction(android.content.Intent.ACTION_VIEW); html_int.setDataAndType(Uri.fromFile(file), "application/htmlviewer"); try { startActivity(html_int); } catch (ActivityNotFoundException e) { Toast.makeText(this, "Sorry, couldn't find a HTML view", Toast.LENGTH_SHORT).show(); } } } } }