/** * Click handler for the library directory preference. * @param preference The actual preference. * @return Always {@code true}, since we always handle the click. */ private boolean onLibDirPrefClick(Preference preference) { if (!Util.checkForStoragePermAndFireEventIfNeeded(R.id.action_choose_lib_dir)) return true; // Set up most of dialog. Our SettingsActivity is the only possible host for this fragment. FolderChooserDialog.Builder builder = new FolderChooserDialog.Builder((SettingsActivity) getActivity()) .chooseButton(R.string.ok) .cancelButton(R.string.cancel); // Check to see if the current value is a valid folder. String folderPath = prefs.getLibDir(null); if (folderPath != null && new File(folderPath).exists()) builder.initialPath(folderPath); // Show the folder chooser dialog. builder.show(); return true; }
private DownloadOptionItem downloadLocationOption() { return new DownloadOptionItem(DownloadOptionIds.DownloadLocation, R.drawable.directory, R.string.download_location, CheckPreferences.getDownloadLocation(mContext), new View.OnClickListener() { @Override public void onClick(View v) { new FolderChooserDialog.Builder((MainActivity)mContext) .chooseButton(R.string.md_choose_label) .tag(FOLDER_CHOOSER_TAG) .initialPath(mDownloadLocation) .allowNewFolder(true, R.string.new_folder) .show(); } } ); }
@Override public void onFolderSelection(@NonNull FolderChooserDialog folderChooserDialog, @NonNull File folder) { try { MaintenanceFragment f = (MaintenanceFragment) getSupportFragmentManager() .findFragmentById(R.id.container); f.exportPersonalKey(this, new FileOutputStream(new File(folder, PersonalKeyPack.KEYPACK_FILENAME))); } catch (FileNotFoundException e) { Log.e(PreferencesFragment.TAG, "error exporting keys", e); Toast.makeText(this, R.string.err_keypair_export_write, Toast.LENGTH_LONG).show(); } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @OnClick(R.id.folder_chooser) public void showFolderChooser() { chooserDialog = R.id.folder_chooser; if (ActivityCompat.checkSelfPermission( MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions( MainActivity.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_RC); return; } new FolderChooserDialog.Builder(MainActivity.this) .chooseButton(R.string.md_choose_label) .allowNewFolder(true, 0) .show(); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @OnClick(R.id.folder_chooser) public void showFolderChooser() { chooserDialog = R.id.folder_chooser; if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_RC); return; } new FolderChooserDialog.Builder(MainActivity.this) .chooseButton(R.string.md_choose_label) .allowNewFolder(true, 0) .show(); }
@Override public void onFolderSelection(@NonNull FolderChooserDialog dialog, @NonNull File folder) { if (l!=null) { Media.init(this, false); Media.invalidate(); l.onFolderSelected(folder); } }
/** * Show the folder chooser when that button is clicked. */ private void onOpenFolderChooserClick() { if (!Util.checkForStoragePermAndFireEventIfNeeded(R.id.action_choose_lib_dir)) return; // Set up most of dialog. FolderChooserDialog.Builder builder = new FolderChooserDialog.Builder(this) .chooseButton(R.string.ok) .cancelButton(R.string.cancel); // Check to see if the current value is a valid folder. String folderPath = Minerva.prefs().getLibDir(null); if (folderPath != null && new File(folderPath).exists()) builder.initialPath(folderPath); // Show the folder chooser dialog. builder.show(); }
/** * Callback from folder chooser dialog shown when the library directory textview is clicked. * @param folder Chosen folder. */ @Override public void onFolderSelection(@NonNull FolderChooserDialog dialog, @NonNull File folder) { // Updating this preference cause the fragment to notice and update the summary for the library directory // preference, since the fragment implements OnSharedPreferenceChangeListener. Minerva.prefs().putLibDir(folder.getAbsolutePath()); }
/** * What to do when the button on the importer view is clicked. */ @OnClick(R.id.import_button) void onButtonClick() { switch (currBtnState) { case START_IMPORT: if (!Util.checkForStoragePermAndFireEventIfNeeded(R.id.action_import)) return; Importer.get().queueFullImport(); break; case CANCEL_IMPORT: Importer.get().cancelImportRun(); break; case CHOOSE_DIR: if (!Util.checkForStoragePermAndFireEventIfNeeded(R.id.action_choose_lib_dir)) return; // Set up most of dialog. FolderChooserDialog.Builder builder = new FolderChooserDialog.Builder(this) .chooseButton(R.string.ok) .cancelButton(R.string.cancel); // Check to see if the current value is a valid folder. String folderPath = Minerva.prefs().getLibDir(null); if (folderPath != null && new File(folderPath).exists()) builder.initialPath(folderPath); // Show the folder chooser dialog. builder.show(); break; } }
@Override public void onFolderSelection(@NonNull FolderChooserDialog dialog, @NonNull File folder) { String path = folder.getAbsolutePath(); Minerva.prefs().putLibDir(path); needsToChooseDir = false; // Pretend this got called with READY. onImportStateChanged(Importer.State.READY); }
@Override public void onFolderSelection(@NonNull FolderChooserDialog dialog, @NonNull File directory) { String tag = dialog.getTag(); switch(tag) { case SettingsFragment.FOLDER_CHOOSER_TAG: if (directory.canWrite()) { CheckPreferences.setDownloadLocation(this, directory.getPath()); SettingsFragment.updatePreferenceSummary(); } else { Toast.makeText(this, R.string.unable_to_select_sd_card, Toast.LENGTH_LONG).show(); ApplicationLogMaintainer.sendBroadcast(this, "Unable to write on selected directory :"); ApplicationLogMaintainer.sendBroadcast(this, directory.getAbsolutePath()); } break; case DownloadOptionAdapter.FOLDER_CHOOSER_TAG: if (directory.canWrite()) { DownloadOptionAdapter downloadOptionAdapter = (DownloadOptionAdapter) mDownloadDialogRecyclerView.getAdapter(); downloadOptionAdapter.setDownloadLocation(directory.getPath()); SettingsFragment.updatePreferenceSummary(); } else { Toast.makeText(this, R.string.unable_to_select_sd_card, Toast.LENGTH_LONG).show(); ApplicationLogMaintainer.sendBroadcast(this, "Unable to write on selected directory :"); ApplicationLogMaintainer.sendBroadcast(this, directory.getAbsolutePath()); } } }
@Override public void onFolderSelection(@NonNull FolderChooserDialog dialog, @NonNull File folder) { // TODO final String tag = dialog.getTag(); // gets tag set from Builder, if you use multiple dialogs Toast.makeText(getActivity(), tag, Toast.LENGTH_LONG).show(); }
@Override public void onFolderSelection(@NonNull FolderChooserDialog dialog, @NonNull File folder) { showToast(folder.getAbsolutePath()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.dialog_excluded_folders); ButterKnife.bind(this); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); Window window = getWindow(); lp.copyFrom(window.getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; window.setAttributes(lp); toolbar.setTitle(R.string.exclude_folders); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_48px); toolbar.setNavigationOnClickListener(this); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new FolderChooserDialog.Builder(reference) .chooseButton(R.string.md_choose_label) .show(); } }); prefString = PreferenceManager.getDefaultSharedPreferences(getContext()).getString("excluded_folders",""); if (prefString.isEmpty()) { folders = new ArrayList<>(); } else { folders = new ArrayList<>(Arrays.asList(prefString.split(":"))); } adapter = new ExcludedFoldersAdapter(getContext()); recycler.setLayoutManager(new LinearLayoutManager(getContext())); recycler.setAdapter(adapter); adapter.update(folders); adapter.getOnClickObservable().subscribe(this); }
@Override public void onFolderSelection(@NonNull FolderChooserDialog dialog, @NonNull File folder) { String path = folder.getAbsolutePath(); Minerva.prefs().putLibDir(path); setFolderText(path); }
@Override public void onFolderSelection(@NonNull FolderChooserDialog dialog, @NonNull File file) { if (findFolderCallback != null) { findFolderCallback.onFolderSelection(dialog, file); } }
public void setFindFolderCallback(FolderChooserDialog.FolderCallback findFolderCallback) { this.findFolderCallback = findFolderCallback; }
@Override public void onFolderChooserDismissed(@NonNull FolderChooserDialog dialog) { }
@Override public void onFolderSelection(FolderChooserDialog dialog, File folder) { showToast(folder.getAbsolutePath()); }
@Override public void onFolderChooserDismissed(FolderChooserDialog dialog) { showToast("Folder chooser dismissed!"); }
@Override public void setFindFolderCallback(FolderChooserDialog.FolderCallback folderCallback) { }
@Override public void onFolderSelection(@NonNull FolderChooserDialog dialog, @NonNull File folder) { }