com.obsez.android.lib.filechooser.ChooserDialog Java Examples

The following examples show how to use com.obsez.android.lib.filechooser.ChooserDialog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PreferenceUtil.java    From habpanelviewer with GNU General Public License v3.0 6 votes vote down vote up
static void loadSharedPreferencesFromFile(Activity ctx, View v) {
    new ChooserDialog(ctx)
            .withFilter(file -> "HPV.prefs".equals(file.getName()) || file.isDirectory())
            .withStartFile(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DOCUMENTS).getPath())
            .withResources(R.string.choose_file, R.string.okay, R.string.cancel)
            .withChosenListener((path, pathFile) -> {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
                try {
                    loadSharedPreferencesFromFile(ctx, pathFile);

                    if (UiUtil.themeChanged(prefs, ctx)) {
                        UiUtil.showSnackBar(v, R.string.themeChangedRestartRequired, R.string.action_restart,
                                view -> EventBus.getDefault().post(new Constants.Restart()));
                    } else {
                        UiUtil.showSnackBar(v, R.string.prefsImported);
                    }
                } catch (IOException | ClassNotFoundException e) {
                    e.printStackTrace();
                    UiUtil.showSnackBar(v, R.string.prefsImportFailed);
                }
            })
            .build()
            .show();
}
 
Example #2
Source File: PreferenceUtil.java    From habpanelviewer with GNU General Public License v3.0 5 votes vote down vote up
static void saveSharedPreferencesToFile(Context ctx, View v) {
    ChooserDialog d = new ChooserDialog(ctx)
            .withFilter(true, false)
            .withStartFile(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DOCUMENTS).getPath())
            .withResources(R.string.chooseTargetDirectory, R.string.okay, R.string.cancel)
            .withChosenListener((path, pathFile) -> saveSharedPreferencesToFile(ctx, v, new File(path, "HPV.prefs")));

    d.build().show();
}
 
Example #3
Source File: FileChooser.java    From ssj with GNU General Public License v3.0 5 votes vote down vote up
public FileChooser(Activity activity, String startPath, boolean dirOnly, String... extensions)
{
	chooserDialog = new ChooserDialog().with(activity);
	chooserDialog.withStartFile(startPath);
	chooserDialog.withFilter(dirOnly, false, extensions);

	chooserDialog.withChosenListener(new ChooserDialog.Result()
	{
		@Override
		public void onChoosePath(String path, File pathFile)
		{
			onResult(path, pathFile);
		}
	}).build();
}
 
Example #4
Source File: SubscriptionsBackupsManager.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Display file picker to be used by the user to select the BACKUP (database) or
 * YOUTUBE SUBS (xml file) to import.
 *
 * @param importDb  If set to true, the app will import (previously backed-up) database;
 *                  Otherwise, it will import YouTube subs (xml file).
 */
private void displayFilePicker(final boolean importDb) {
	// do not display the file picker until the user gives us access to the external storage
	if (!hasAccessToExtStorage(importDb ? EXT_STORAGE_PERM_CODE_IMPORT : IMPORT_SUBSCRIPTIONS_READ_CODE))
		return;

	ChooserDialog dialog = new ChooserDialog(activity)
			.withStartFile(importDb ? Environment.getExternalStorageDirectory().getAbsolutePath() : Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath())
			.displayPath(true)
			.withChosenListener((file, dirFile) -> {
				if (importDb)
					displayImportDbsBackupWarningMsg(file);
				else {
					Uri uri = Uri.fromFile(new File(file));
					parseImportedSubscriptions(uri);
				}
			})
			.withOnCancelListener(dialog1 -> {
				dialog1.cancel();
			});
	if(importDb) {
		dialog.withFilter(false, false, "skytube");
	} else {
		dialog.withFilterRegex(false, false, ".*(xml|subscription_manager)$");
	}
	dialog.build().show();
}